/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.cms.column.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.jeeplus.cms.support.validation.PatternExtend;
import com.jeeplus.core.persistence.TreeEntity;
import com.jeeplus.modules.cms.model.entity.CmsModel;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * 栏目Entity
 *
 * @author Sawyer
 * @version 2020-11-21
 */
@Getter
@Setter
@ToString
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler"})
public class CmsColumn extends TreeEntity<CmsColumn> {

    private static final long serialVersionUID = 1L;

    @NotNull(message = "栏目模型不能为空")
    private CmsModel model;

    private String image;

    @URL(message = "链接无效")
    private String href;

    /**
     * 启用标记
     */
    @PatternExtend(regexp = "^[0-1]$", required = true, message = "标记无效")
    private String enableFlag;

    /**
     * 首页显示标记
     */
    @PatternExtend(regexp = "^[0-1]$", required = true, message = "标记无效")
    private String homeFlag;

    /**
     * 允许评论标记
     */
    @PatternExtend(regexp = "^[0-1]$", required = true, message = "标记无效")
    private String commentFlag;

    /**
     * 需要审核标记
     */
    @PatternExtend(regexp = "^[0-1]$", required = true, message = "标记无效")
    private String auditFlag;

    @PatternExtend(regexp = "^.{2,127}$", message = "关键字长度应为2-127个字符")
    private String keywords;

    @PatternExtend(regexp = "^.{2,127}$", message = "描述长度应为2-127个字符")
    private String description;

    @PatternExtend(regexp = "^.{1,3000}$", message = "参数配置最大长度不能超过3000")
    private String paramConfig;

    private Integer hits;

    /**
     * 信息点击量
     */
    private Integer infoCount;

    /**
     * 详情点击量
     */
    private Integer detailsHits;

    /**
     * 是否有子节点
     */
    private Boolean hasChildren;

    /**
     * 所属站点
     */
    @NotBlank(message = "所属站点不能为空")
    private String siteId;


    public CmsColumn() {
        super();
        this.setIdType(IDTYPE_AUTO);
    }

    public CmsColumn(String id) {
        super(id);
        this.setIdType(IDTYPE_AUTO);
    }

    /**
     * 初始化数据
     */
    public void init() {
        this.setHits(0);
    }

    @Override
    public CmsColumn getParent() {
        return parent;
    }

    @Override
    public void setParent(CmsColumn parent) {
        this.parent = parent;

    }

    @Override
    public String getParentId() {
        return parent != null && parent.getId() != null ? parent.getId() : "0";
    }

}
